<!--[if IE 9]>
<link rel="stylesheet" href="components/com_frmessage/public/css/ie9.css" type="text/css" />
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" href="components/com_frmessage/public/css/ie8.css" type="text/css" />
<![endif]-->
<script>
jq(document).ready(function(){
    jq('.toolbar').click(function(){
        var task = jq(this).attr('id');
        var flag = true;

        if(task == 'save'){
            if(!jq('#OCBA_CODE_LIST').val()){
                alert('宛先を入力（または選択）してください。');
                return false;
            }

            if(!jq('#TITLE').val()){
                alert('件名入力ください。');
                return false;
            }
        }

        if(task == 'delete'){
            flag = false;
            if(confirm('選択されたメッセージを削除します。よろしいですか？')){
                jq('#task').val( task );
                jq('#adminForm').submit();
            }
        }

        jq('#task').val( task );

        if(flag == true){
            jq('#adminForm').submit();
        }

        return false;
    }) // END click tool bar



    // onchange folder
    jq('#folders').change(function(){
        $this = jq(this);
        if($this.val()){
            jq('#task').val( 'folders' );
            jq('#adminForm').submit();
        }
    });

    // class confirm
    jq('.confirmTrash').click(function(e){
        e.preventDefault();
        $this = jq(this);
        jq.Zebra_Dialog('<strong>'+$this.attr('title')+'</strong>', {
                'type':     'question',
                'title':    'Confirm',
                'buttons':  [
                                {caption: 'No', callback: function() {}},
                                {caption: 'Yes', callback: function() {
                                    window.location.href = $this.attr('href');
                                }}
                            ]
            });
    })
})
</script>

<?php
$db = JFactory::getDbo();
$idUser = JFactory::getUser()->username;
$query = "SELECT * FROM fome WHERE FOME_USEM_CODE = '$idUser'";

$db->setQuery($query);
$folders = $db->loadObjectList();

if(!$folders){
    $folders = (object)$folders;
}

$listFolder = array();
foreach($folders as $fol){
    $listFolder[$fol->FOME_PARENT][] = $fol;
}

if($listFolder[0]){
    $folders = array();
    foreach($listFolder[0] as $fol){
        $folders[] = $fol;
        if($listFolder[$fol->FOME_CODE]){
            foreach($listFolder[$fol->FOME_CODE] as $f){
                $f->FOME_NAME = '|___'.$f->FOME_NAME;
                $folders[] = $f;
            }
        }
    }
}

$menus = array('inbox'=>'受信トレイ', 'sent'=>'送信済み', 'draft'=>'下書き', 'trash'=>' ゴミ箱');
?>

<div id="jm-left" class="" >
    <div class="jm-module " id="">
       <div class="jm-module-content">
          <h3 class="jm-title">メッセージ（一覧）</h3>
          <div class="content-message">
            <div>
                <ul id="menu-left">
                    <?php foreach($menus as $k=>$v){
                        $active = JRequest::getVar('cate') == $k ? 'active' : null;
                        $empty = $k == 'trash' ? '<a class="confirmTrash" title="選択したデータを削除します。よろしいですか？" href="index.php?top=page&option=com_frmessage&task=emptyTrash" style="margin-left: 8%;">空にする</a>' : null;
                       echo  "<li class='$active'><a href='index.php?top=page&option=com_frmessage&cate=$k'>■&nbsp;$v</a>$empty</li>";
                    }?>
                    <li>■&nbsp;個人用フォルダ
                        <button href="index.php?top=page&option=com_frmessage&view=folder" class="ie7-buttonfolder">フォルダ一覧</button>
                    </li>
                      <?php foreach($folders as $folder){
                                $active = JRequest::getVar('id') == $folder->FOME_CODE && JRequest::getVar('cate') == 'folder' ? 'active' : null;
                                $str = $folder->FOME_PARENT ? '' : '■&nbsp;';
                                echo "<li class='$active'>&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href='index.php?top=page&option=com_frmessage&cate=folder&id=$folder->FOME_CODE'>
                                        $str $folder->FOME_NAME
                                    </a></li>";
                            }?>
                </ul>
              </div>

          </div>
          <div class="clearfix"></div>

       </div>
    </div>

 </div>